package com.example.eschool;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.eschool.bean.Message;

import java.util.List;

public class MessageAdapter extends BaseAdapter {

    private Context context;
    private List<Message> messageList;

    public MessageAdapter(Context context,List<Message> messageList) {
        this.context = context;
        this.messageList = messageList;
    }

    @Override
    public int getCount() {
        return messageList.size();
    }

    @Override
    public Object getItem(int position) {
        return messageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    static class ViewHolder{
        TextView title,time,money,tong_zhi,miao_shu;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView==null){
             convertView = LayoutInflater.from(context).inflate(R.layout.message_center, parent, false);
            holder = new ViewHolder();
            holder.title = convertView.findViewById(R.id.message_title);
            holder.money = convertView.findViewById(R.id.message_money);
            holder.tong_zhi = convertView.findViewById(R.id.message_tong_zhi);
            holder.time = convertView.findViewById(R.id.message_time);
            holder.miao_shu = convertView.findViewById(R.id.message_miao_shu);

            convertView.setTag(holder);
        }else {
             holder = (ViewHolder) convertView.getTag();

        }
        Message item = messageList.get(position);
        holder.title.setText(item.getTitle());
        holder.time.setText(item.getTime());
        holder.money.setText(item.getMoney());
        holder.tong_zhi.setText(item.getTong_zhi());
        holder.miao_shu.setText(item.getMiao_shu());

        return convertView;
    }


}
